<% layout('/layouts/default.html', {title: '自媒体管理', libs: ['layout','zTree','dataGrid','validate','fileupload']}){ %>
<style>
	.lehand_title{
		line-height: 50px;
		text-align: center;
		font-size: 16px;
		color: #000000;
		margin-top: -10px;
		border-bottom: 1px solid #cccccc;
	}
	.lehand_title_ul{
		width: 100%;
		text-align: left;
	}
	.lehand_title_ul a{
		display: block;
		margin:0px;
		list-style: none;
		font-size: 14px;
		line-height: 35px;
		color: #000000;
		cursor: pointer;
	}
	.lehand_title_ul a:hover{
		color: #3c8dbc;
	}

	.lehand_title a{
		color: #000000;
		cursor: pointer;
	}
	.lehand_title a:hover{
		color: #3c8dbc;
	}
	.activeTi{
		color: #3c8dbc !important;
	}
	.btn-group-sm>.btn, .btn-sm {
		padding: 6px 12px;
		font-size: 14px;
		line-height: 1.3;
		height: 40px;
		margin-left: 20px;
		margin-top: 5px;
	}
	.ui-layout-pane-north {
		height: 50px;
		position: absolute;
		margin: 0px;
		inset: 0px 0px auto;
		width: auto;
		z-index: 0;
		display: block;
		visibility: visible;
	}
	.ui-content .content-open {
		display: none;
	}

	.ui-layout-toggler .ui-content .fa {
		line-height: 8px;
		display: none;
	}
	.ui-jqgrid {
		animation-duration: .5s;
		animation-name: fadeIn;
		height:600px;
	}
	.ui-layout-content {
		padding: 10px;
		position: relative;
		overflow: hidden;
		width: 100%;
		border: 0;
	}
</style>
<div class="ui-layout-north" style="height: 50px">
	<button type="button" class="btn btn-sm btn-default btnList" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('返 回')}</button>
</div>
<div class="ui-layout-west">
	<div class="main-content">
		<div class="box box-main">
			<div class="box-header" style="padding-bottom: 4px;">
				<div class="box-title">
					<i class="fa icon-grid"></i> ${text('指标报送单位')}
				</div>
			</div>
			<div class="box-body">
				<div class="input-group">
					<#form:input path="createOrgName" maxlength="100" class="form-control " placeholder="输入单位名称" autocomplete="off"/>
					<span class="input-group-addon"  style="cursor: pointer" onclick="changeExamOrg()">查询</span>
					<span class="input-group-addon" onclick="reset()" style="cursor: pointer">重置</span>
				</div>
			</div>
			<div class="ui-layout-content">
				<table id="leftDataGrid"></table>
			</div>
		</div>
	</div>
</div>
<div class="ui-layout-center">
	<iframe id="mainFrame" name="mainFrame" class="ui-layout-content p0"></iframe>
</div>
<% } %>
<script>
	var examOrgList = [];
	// 初始化布局
	$('body').layout({
		west__initClosed: $(window).width() <= 767, // 是否默认关闭
		west__size: 250,
		onresize_end: function(){
			$('#leftDataGrid').dataGrid('resize');
		}
	});
	// 主页框架
	var win = $("#mainFrame")[0].contentWindow;

	//根据单位名称搜索考核单位
	function changeExamOrg() {
		//$(".lehand_title_ul").empty();
		var createOrgName = $("#createOrgName").val();
		var formdata={"createOrgName":createOrgName,"examYear":'${dcSupExamQuota.examYear}',"examId":'${dcSupExamQuota.examId}'};
		//findcreateorg1();
		// 刷新表格数据
		$('#leftDataGrid').dataGrid('setParam', {
			postData:formdata
		}, true).dataGrid('reloadGrid');
	}
	// 主页框架
	$(function () {
		//查询被考核单位
		findcreateorg();
	});

	//查询被考核单位
	var createorg='';
	var fileStatus='2';

	// 调用子页分页函数
	function page(){
		win.page();
	}

	let baseData;

    //查询被考核单位数据
	function findcreateorg() {
		var createOrgName = $("#createOrgName").val();
		var formdata={"createOrgName":createOrgName,"examYear":'${dcSupExamQuota.examYear}',"examId":'${dcSupExamQuota.examId}'};
		$('#leftDataGrid').dataGrid({
			url: '${ctx}/targetAudit/exameOrgListData',
			postData: formdata,
			sortableColumn:false, // 禁止排序
			showRownum: false,
			columnModel: [
				/*{header:'${text("任务id")}', name:'examId',hidden:true, width:150, align:"left"},*/
				{header:'${text("状态")}', name:'filestatus',hidden:true, width:150, align:"left"},
				{header:'${text("考核单位code")}', name:'createorg',hidden:true, width:150, align:"left"},
				{header:'${text("报送单位")}', name:'createorgname', width:150, align:"left",formatter: function(val, obj, row){
						if (row.filestatus=='1'){
							return val+'<span style="color: red">(未补充)</span>'
						}
						if (row.filestatus=='2'){
							return val+'<span style="color: blue">(未审核)</span>'
						}
						if (row.filestatus=='3'){
							return val+'<span style="color: red">(已退回)</span>'
						}
						if (row.filestatus=='4'){
							return val+'<span style="color: green">(已审核)</span>'
						}
						return val;
					},
					unformat: function(val, obj, cell){
					   return baseData[parseFloat(obj.rowId)-1].createorgname;
				    }
				}
			],
			autoGridHeight: function(){
				var height = $(window).height()-170;
				return height;
			},
			emptyDataHint: true,
			// 选择行后调用（id:行id，isSelect：是否是选中，event：事件）
			onSelectRow: function(id, isSelect, event) {
				let selectRow = $('#leftDataGrid').dataGrid('getRowData', id);
				fileStatus = selectRow.filestatus;
				createorg = selectRow.createorg;
				$('#mainFrame').attr('src', '${ctx}/targetAudit/subView?examId=${dcSupExamQuota.examId}&quotaGroup=2' +
						'&examYear=${dcSupExamQuota.examYear}&createOrg='+createorg+'&fileStatus='+fileStatus+'&examOrgList='+examOrgList+
						'&examTitle=${dcSupExamQuota.examTitle}');
			},
			// 加载成功后执行事件
			ajaxSuccess: function(data){
				if(data.length==0){
					$('#mainFrame').attr('src', '${ctx}/targetAudit/subView?examId=null');
				}
				for (var i = 0 ; i < data.length; i++) {
					examOrgList.push(data[i].createorg);
				}
				$('#leftDataGrid').dataGrid('setSelectRow', 1, false);
				baseData=data;
				js.closeLoading(3000, true);
			}
		});

	}

	// 重置表格数据
	function reset() {
		// 重置查询项
		$("#createOrgName").val('');
		var createOrgName = $("#createOrgName").val();
		var formdata={"createOrgName":createOrgName,"examYear":'${dcSupExamQuota.examYear}',"examId":'${dcSupExamQuota.examId}'};
		// 重置表格数据
		$('#leftDataGrid').dataGrid('setParam', {
			postData:formdata
		}, true).dataGrid('reloadGrid');
	}

	function change(createorg,status){
		var datas=$('#leftDataGrid').dataGrid('getRowData');
		for (let i = 0; i < datas.length; i++) {
			if(datas[i].createorg==createorg){
				datas[i].filestatus=status;
				$('#leftDataGrid').dataGrid('setRowData',(i+1), datas[i]);
				break;
			}
		}
	}
	function orgChange(createorg,status){
		var datas=$('#leftDataGrid').dataGrid('getRowData');
		for (let i = 0; i < datas.length; i++) {
			if(datas[i].createorg==createorg){
				datas[i].filestatus=status;
				$('#leftDataGrid').dataGrid('setRowData',(i+1), datas[i]);
				$('#leftDataGrid').dataGrid('setSelectRow', (i+1), false);
				break;
			}
		}
	}


</script>
